package main

import (
	"gitee.com/mangenotework/slide_block_locator/common/config"
	"gitee.com/mangenotework/slide_block_locator/core"
	"github.com/gin-gonic/gin"
)

func main() {
	config.InitConf() // 初始化配置
	gin.SetMode(gin.DebugMode)
	s := Routers()
	s.Run(":" + config.Arg.HttpServer.Prod)
}


func Routers() *gin.Engine {
	Router := gin.Default()
	Router.POST("/", Handler)
	return Router
}

func Handler(c *gin.Context) {
	f, err := c.FormFile("img")
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1,
			"msg":  "上传失败!",
		})
		return
	}
	ff, err := f.Open()
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1,
			"msg":  "图片读取失败!"+err.Error(),
		})
		return
	}
	out, err := core.GetQueKou(ff)
	if err != nil {
		c.JSON(200, gin.H{
			"code": 1,
			"msg":  "缺口识别失败!"+err.Error(),
		})
		return
	}
	c.JSON(200, gin.H{
		"code": 0,
		"msg":  "缺口寻找成功",
		"data": out,
	})
	return
}